package com.imut.oa.controller.admin;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.PageResult;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.AttendancePageQueryDTO;
import com.imut.oa.pojo.dto.AttendanceRemarkDTO;
import com.imut.oa.pojo.dto.WorkTimeConfigDTO;
import com.imut.oa.pojo.vo.AttendanceVO;
import com.imut.oa.service.AttendanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/attendance")
@Slf4j
@Tag(name = "考勤管理")
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;
    /**
     * 考勤分页查询
     * @param attendancePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "考勤分页查询")
    public BaseResponse<PageResult> page(AttendancePageQueryDTO attendancePageQueryDTO) {
        log.info("考勤分页查询：{}",attendancePageQueryDTO);
        PageResult result = attendanceService.page(attendancePageQueryDTO);
        return ResultUtils.success(result);
    }

    /**
     * 考勤备注
     * @param attendanceRemarkDTO
     * @return
     */
    @PutMapping("/remark")
    @Operation(summary = "考勤备注")
    public BaseResponse approve(@RequestBody AttendanceRemarkDTO attendanceRemarkDTO) {
        log.info("考勤备注：{}",attendanceRemarkDTO);
        attendanceService.updateRemark(attendanceRemarkDTO);
        return ResultUtils.success();
    }
    /**
     * 获取上班时间和下班时间的配置
     * @return
     */
    @GetMapping("/worktimeconfig")
    @Operation(summary = "获取上班时间和下班时间的配置")
    public BaseResponse<WorkTimeConfigDTO> getWorkTimeConfig() {
        log.info("获取上班时间和下班时间的配置");
        WorkTimeConfigDTO config = attendanceService.getWorkTimeConfig();
        return ResultUtils.success(config);
    }
    /**
     * 更新上班时间和下班时间的配置
     * @param workTimeConfigDTO
     * @return
     */
    @PutMapping("/worktimeconfig")
    @Operation(summary = "更新上班时间和下班时间的配置")
    public BaseResponse updateWorkTimeConfig(@RequestBody WorkTimeConfigDTO workTimeConfigDTO) {
        log.info("更新上班时间和下班时间的配置：{}", workTimeConfigDTO);
        int updateCount = attendanceService.updateWorkTimeConfig(workTimeConfigDTO);
        if (updateCount > 0) {
            return ResultUtils.success(null,"打卡时间修改成功");
        } else {
            throw new RuntimeException("更新失败");
        }
    }
}
